package org.NooLab.nativebrowser.components;

import java.awt.event.MouseEvent;

import javax.swing.JFrame;


import org.NooLab.nativebrowser.WebBrowserApp;
import org.NooLab.nativebrowser.app.config.NNBAppProperties;
import org.NooLab.nativebrowser.app.config.ITexxAppPropertiesIntf;
import org.NooLab.nativebrowser.app.controller.ClipboardConsumerIntf;
import org.NooLab.nativebrowser.app.controller.ExitActionProviderIntf;
import org.NooLab.nativebrowser.app.controller.HtmlConsumer;
import org.NooLab.nativebrowser.app.controller.HtmlConsumerIntf;
import org.NooLab.nativebrowser.app.controller.ItexxModelController;

import org.NooLab.nativebrowser.browser.BrowserHostList;
import org.NooLab.nativebrowser.gui.hidden.HiddenWindowGuiIntf;
import org.NooLab.utilities.clipboard.CBoardProperties;
import org.NooLab.utilities.clipboard.CBoardPropertiesIntf;
import org.NooLab.utilities.clipboard.ClipBoardIntf;
import org.NooLab.utilities.clipboard.ClipBoardListener;
import org.NooLab.utilities.logging.PrintLog;
import org.NooLab.utilities.timing.DelayNotificationIntf;







public class NativeBrowserCommons {

	WebBrowserAppMainIntf app;
	ITexxAppPropertiesIntf appProperties ;

	BrowserHostList hostList;
	private JFrame frame;
	private HiddenWindowGuiIntf windowGui;
	
	// -----------------------------------------------------	
	
	private ClipBoardListener clipboard;
	String lastClipboardContent = "";
	// -----------------------------------------------------

	private ClipboardConsumerIntf consumer;

	private HtmlConsumer htmlConsumer=null;
	private ItexxModelController modelController;
	private boolean guiWorkerIsWorking;
	
	public PrintLog out = new PrintLog(2,false);
	private WebBrowserPublicIntf exposureClient;
	
	// ========================================================================
	private NativeBrowserCommons(WebBrowserAppMainIntf app){
		this.app = app;
		
		windowGui = app.getWindowGui() ;
		
		out.setPrefix("[ITEXX]");
	}
	
	

	public static NativeBrowserCommons getInstance(WebBrowserAppMainIntf app) {
		
		NativeBrowserCommons _commons = new NativeBrowserCommons(app);
		
		
		
		return _commons;
	}
	// ========================================================================
	

	public void performClose(WebBrowserApp app2) {

		
	}

	public void setBrowserHostList(BrowserHostList hostlist) {
		// 
		hostList = hostlist ;
	}

	public WebBrowserAppMainIntf getApp() {
		return app;
	}

	public WebBrowserPublicIntf getExposureClient() {
		// 
		return exposureClient;
	}
	public void setExposureClient(WebBrowserPublicIntf client) {
		// 
		exposureClient = client;
	}



	public ITexxAppPropertiesIntf getAppProperties() {
		return appProperties;
	}

	public void setFrameReference(JFrame frame) {
		
		this.frame = frame ;
		
	}

	public JFrame getFrame() {
		return frame;
	}

	public void setWindowGui(HiddenWindowGuiIntf windowgui) {
		windowGui = windowgui ;
		windowGui.setAppCommons(this) ;
		

	}
	
	public HiddenWindowGuiIntf getWindowGui() {
		return windowGui;
	}

	public BrowserHostList getHostList() {
		return hostList;
	}



	public HtmlConsumerIntf getHtmlConsumer() {
		// 
		return htmlConsumer;
	}

	public HtmlConsumerIntf createHtmlConsumer() {
		
		htmlConsumer = new HtmlConsumer(app);
		return htmlConsumer ;
	}




	public boolean isEarlyPreprocessing() {
		// 
		boolean rB = appProperties.isEarlyPreprocessing();
		
		if (rB){
			
		}
		return rB;
	}
	
	public boolean isEarlyPreprocessing(String urlstr) {
		// 
		boolean rB = appProperties.isEarlyPreprocessing();
		
		if ((rB) && (urlstr.length()==0)){
			rB=false;
		}
		if (rB){
			rB = urlstr.toLowerCase().contains(".google.");
			if (rB==false){
				rB = urlstr.toLowerCase().contains(".bing.");
			}
			if (rB==false){
				rB = urlstr.toLowerCase().contains(".yahoo.");
			}
		}
		return rB;
	}

	public void setModelController(ItexxModelController modelController) {
		// this object is owned by the Gui component... important, if we change it!
		this.modelController = modelController;
	}

	public ItexxModelController getModelController() {
		return modelController;
	}


	public JFrame getMainFrame() {
		// 

		JFrame frame = app.getMainFrame();// (new GuiWorker( app,true,1f)).getFrame();
		return frame;
	}

	public void setGuiWorkerIsWorking(boolean flag) {
		guiWorkerIsWorking = flag;
		
	}
	public boolean getGuiWorkerIsWorking(){
		return guiWorkerIsWorking; 
	}



	public void setProperties(ITexxAppPropertiesIntf properties) {
		appProperties = properties;
		appProperties.setCommonsReference(this);
	}



	public PrintLog getOut() {
		//
		return out;
	}



	

	
}
